import torchvision
import torch
from deep.model import Net

"""
写代码时测试使用的文件,非正式代码
"""

net = Net(num_classes=1,reid=False)


mapl = torch.device("cpu")
checkpoint = torch.load("./deep/checkpoint/ckpt.t7",map_location=mapl)
# import ipdb; ipdb.set_trace()
print(f"checkpoints.keys = {checkpoint.keys()}")
net_dict = checkpoint['net_dict']
with open("ckpt.t7.txt","w",encoding="utf-8") as fp:
    fp.write(f"{net_dict}")
with open("ckpt.t7.keys()","w",encoding="utf-8") as fp:
    fp.write(f"{net_dict.keys()}")
# print(f"net_dict = {net_dict}")
net.load_state_dict(net_dict)
best_acc = checkpoint['acc']
print(f"best_acc = {best_acc}")
# best_acc = 100.0
start_epoch = checkpoint['epoch']
print(f"start_epoch = {start_epoch}")
# start_epoch = 0


import numpy as np
for name,param in net.named_parameters():
    print(f"name = {name} , shape = {np.shape(param)}")



# # print(datasets.class_to_idx)
# # {'bag01': 0, 'bag02': 1, 'bag03': 2, 'bag04': 3, 'bag05': 4, 'bag06': 5, 'bag07': 6, 'bag08': 7, 'bag09': 8, 'bag10': 9, 'bag11': 10}
# # print(datasets.imgs)
# # print(datasets[0])

# trans = torchvision.transforms.Compose([
#     torchvision.transforms.RandomCrop((128, 64), padding=4,pad_if_needed=True),
#     torchvision.transforms.RandomHorizontalFlip(),
#     torchvision.transforms.ToTensor(),
#     torchvision.transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
# ])

# dataset = torch.utils.data.DataLoader(
#     torchvision.datasets.ImageFolder("./data/train", transform=trans),
#     batch_size=64, shuffle=False
# )
# # print(dataset.class_to_idx)

# for id , (img , label) in enumerate(dataset):
#     print(id)
#     print(img)
#     print(label)
#     break


